﻿namespace BM.Tools.WebControls.MForm.Controls.Helper.EventValidation
{
    using System;
    using System.Collections.Generic;
    using System.Linq;

    /// <summary>
    /// A list of <see cref="EventValidationNode" /> that also keeps the id prefix and id suffixes.
    /// </summary>
    internal class EventValidationNodeList : List<EventValidationNode>
    {
        /// <summary>
        /// Gets or sets possible suffixes.
        /// </summary>
        public List<string> Suffixes
        {
            get; 
            set;
        }

        /// <summary>
        /// Gets or sets the prefix.
        /// </summary>
        public string Prefix
        {
            get; 
            set;
        }

        /// <summary>
        /// Performs a deep clone.
        /// </summary>
        /// <returns>
        /// A deep clone.
        /// </returns>
        public EventValidationNodeList Clone()
        {
            var clone = new EventValidationNodeList
            {
                Prefix = Prefix
            };
            clone.AddRange(this);
            return clone;
        }

        /// <summary>
        /// Creates a hash name.
        /// </summary>
        /// <param name="idSeparator">
        /// The id Separator.
        /// </param>
        /// <returns>
        /// A hash name of the list.
        /// </returns>
        public string GetHashName(char idSeparator)
        {
            return String.Join(idSeparator.ToString(), this.Select(node => node.Name).ToArray());
        }
    }
}
